<?php

class DefaultController extends Controller
{
	public $layout = 'default';
	public function filters()
	{
		return array(
			'accessControl',
		);
	}
	/**
	 * Specifies the access control rules.
	 * This method is used by the 'accessControl' filter.
	 * @return array access control rules
	 */
	public function accessRules()
	{
		return array(
			array('allow',
				'actions'=>array('index', 'error'),
				'users'=>array('*'),
			),
			array('allow',
				'actions'=>array(''),
				'users'=>array('?'),
			),
			array('allow',
				'actions'=>array(''),
				'users'=>array('@'),
			),
			array('deny',
				'users'=>array('*'),
			),
		);
	}
	public function actionIndex()
	{
		$criteria = new CDbCriteria();
		//$criteria->limit = 9;
		$criteria->order = 'posteddate DESC';
		$dataProvider=new CActiveDataProvider('Products',
			array(
				'criteria'=>$criteria,
				'pagination'=>array(
					'pageSize'=>9,
				),
			)
		);
		$category= Categories::model()->findAll("parent_id != 0");
		$this->render('index',array(
			'dataProvider'=>$dataProvider,
			'category'=>$category
		));
	}
	/**
	 * This is the action to handle external exceptions.
	 */
	public function actionError()
	{
		if($error=Yii::app()->errorHandler->error)
		{
			if(Yii::app()->request->isAjaxRequest)
				echo $error['message'];
			else
				$this->render('error', $error);
		}
	}
}